package edu.neu.cs6515.net.test.unit;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;


import edu.neu.cs6515.net.IProxyInOutput;
import edu.neu.cs6515.net.InputOutputException;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
 * a input output class which recieves a predefined sequence of 
 * messages
 */
@NoArgsConstructor
public class PredefinedInOutPut implements IProxyInOutput {

    BlockingQueue<Object> queue = new ArrayBlockingQueue<Object>(1);

    @Getter @Setter
    private List<Object> responses = new LinkedList<Object>();
    @Getter @Setter
    private List<Object> receives = new LinkedList<Object>();
    
    /**
     * pop the oldest response from response buffer
     * @return
     */
    public Object popOldestResponse(){
        return responses.remove(0);
    }
    

    @Override
    public void respond(final Object obj) throws InputOutputException {
        responses.add(obj);
    }

    @Override
    public Object receive() throws InputOutputException {
        if(receives.size() > 0){
        return receives.remove(0);
        }else{
            throw new InputOutputException("end of input output");
        }
    }

}
